<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>Laya FairyGui系列一  FairyGui接入 | Vitiu</title>
  <meta name="description" content="一，什么是FairyGuiFairyGUI(下面简称FGUI)提供了一个强大的UI编辑器，使用习惯与Adobe系列软件保持一致，美术设计师和策划都可以轻松上手。与市场上其他UI编辑器不同…。一堆介绍不抄了，有兴趣得自己去看官网。我选择FairyGUI的最大的原因就是对策划和美术人员比(zi)较(ji)友(tou)好(lan)，学习成本较低，组件完善，不用任何扩展UI也能实现奇葩的UI需求。预览效果">
<meta name="keywords" content="Laya,FairyGui">
<meta property="og:type" content="article">
<meta property="og:title" content="Laya FairyGui系列一  FairyGui接入">
<meta property="og:url" content="http:&#x2F;&#x2F;yoursite.com&#x2F;2019&#x2F;11&#x2F;23&#x2F;FairyGui%E6%8E%A5%E5%85%A5&#x2F;index.html">
<meta property="og:site_name" content="Vitiu">
<meta property="og:description" content="一，什么是FairyGuiFairyGUI(下面简称FGUI)提供了一个强大的UI编辑器，使用习惯与Adobe系列软件保持一致，美术设计师和策划都可以轻松上手。与市场上其他UI编辑器不同…。一堆介绍不抄了，有兴趣得自己去看官网。我选择FairyGUI的最大的原因就是对策划和美术人员比(zi)较(ji)友(tou)好(lan)，学习成本较低，组件完善，不用任何扩展UI也能实现奇葩的UI需求。预览效果">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https:&#x2F;&#x2F;upload-images.jianshu.io&#x2F;upload_images&#x2F;18005075-f3dd5e6386b501ac.png?imageMogr2&#x2F;auto-orient&#x2F;strip%7CimageView2&#x2F;2&#x2F;w&#x2F;1240">
<meta property="og:image" content="https:&#x2F;&#x2F;upload-images.jianshu.io&#x2F;upload_images&#x2F;18005075-5d0a3f521d02983f.png?imageMogr2&#x2F;auto-orient&#x2F;strip%7CimageView2&#x2F;2&#x2F;w&#x2F;1240">
<meta property="og:updated_time" content="2019-11-23T14:11:00.781Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https:&#x2F;&#x2F;upload-images.jianshu.io&#x2F;upload_images&#x2F;18005075-f3dd5e6386b501ac.png?imageMogr2&#x2F;auto-orient&#x2F;strip%7CimageView2&#x2F;2&#x2F;w&#x2F;1240">
  <!-- Canonical links -->
  <link rel="canonical" href="http://yoursite.com/2019/11/23/FairyGui%E6%8E%A5%E5%85%A5/index.html">
  
    <link rel="alternate" href="/atom.xml" title="Vitiu" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/css/style.css">
  
  
  
  
</head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="" target="_blank">
          <img class="img-circle img-rotate" src="/images/avatar.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">V</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Game Developer &amp; Designer</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> AnHui, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Laya-FairyGui/">Laya & FairyGui</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Laya%E6%8F%92%E4%BB%B6/">Laya插件</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/FairyGui/" rel="tag">FairyGui</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JSZip/" rel="tag">JSZip</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Laya/" rel="tag">Laya</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8F%92%E4%BB%B6/" rel="tag">插件</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">3</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/Laya-FairyGui/">Laya & FairyGui</a>
              </p>
              <p class="item-title">
                <a href="/2019/11/23/GObject/" class="title">Laya FairyGui系列二  GObject  GComponent</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-23T12:25:02.000Z" itemprop="datePublished">2019-11-23</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/Laya-FairyGui/">Laya & FairyGui</a>
              </p>
              <p class="item-title">
                <a href="/2019/11/23/FairyGui%E6%8E%A5%E5%85%A5/" class="title">Laya FairyGui系列一  FairyGui接入</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-23T12:22:03.000Z" itemprop="datePublished">2019-11-23</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/Laya%E6%8F%92%E4%BB%B6/">Laya插件</a>
              </p>
              <p class="item-title">
                <a href="/2019/11/23/Laya%E4%BD%BF%E7%94%A8zip%E5%8E%8B%E7%BC%A9%E5%8C%85/" class="title">Laya使用zip压缩包</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-23T11:51:55.000Z" itemprop="datePublished">2019-11-23</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="laya-FairyGui接入" class="article article-type-laya" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      Laya FairyGui系列一  FairyGui接入
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/2019/11/23/FairyGui%E6%8E%A5%E5%85%A5/" class="article-date">
	  <time datetime="2019-11-23T12:22:03.000Z" itemprop="datePublished">2019-11-23</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/categories/Laya-FairyGui/">Laya & FairyGui</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/tags/FairyGui/" rel="tag">FairyGui</a>, <a class="article-tag-link" href="/tags/Laya/" rel="tag">Laya</a>
  </span>


        

        <!-- <span class="post-comment"><i class="icon icon-comment"></i> <a href="/2019/11/23/FairyGui%E6%8E%A5%E5%85%A5/#comments" class="article-comment-link">评论</a></span> -->
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h1 id="一，什么是FairyGui"><a href="#一，什么是FairyGui" class="headerlink" title="一，什么是FairyGui"></a>一，什么是FairyGui</h1><p>FairyGUI(下面简称FGUI)提供了一个强大的UI编辑器，使用习惯与Adobe系列软件保持一致，美术设计师和策划都可以轻松上手。与市场上其他UI编辑器不同…。一堆介绍不抄了，有兴趣得自己去看<a href="http://www.fairygui.com/guide/index.html" target="_blank" rel="noopener">官网</a>。<br>我选择FairyGUI的最大的原因就是对策划和美术人员比(zi)较(ji)友(tou)好(lan)，学习成本较低，组件完善，不用任何扩展UI也能实现奇葩的UI需求。预览效果中即可看到按钮的不同状态切换，列表的滚动效果，动效的运行效果等等，</p>
<h1 id="二，获取FGUI以及LayaSDK"><a href="#二，获取FGUI以及LayaSDK" class="headerlink" title="二，获取FGUI以及LayaSDK"></a>二，获取FGUI以及LayaSDK</h1><p>FGUI编辑器下载<a href="http://www.fairygui.com/product/" target="_blank" rel="noopener">链接</a>。<br>LayaSDK获取：</p>
<ul>
<li>从官网下载Laya版本的[demo](<a href="http://www.fairygui.com/product/#" target="_blank" rel="noopener">http://www.fairygui.com/product/#</a> LayaAir-SDK)(只有Laya2.0版本的SDK)。</li>
<li>从Github下载Laya版本的<a href="https://github.com/fairygui/FairyGUI-layabox" target="_blank" rel="noopener">demo</a>（可以在分支中选择Laya1.0或者2.0）。<br>本文主要以Laya2.0为例，某些Laya1.0和2.0不同之处会标注</li>
</ul>
<h1 id="三，集成SDK"><a href="#三，集成SDK" class="headerlink" title="三，集成SDK"></a>三，集成SDK</h1><ul>
<li><p>把上面下载的demo中的libs/fairygui.d.ts，bin/libs/fairygui(Laya1.0还需拷贝bin/libs/rawinflate)拷贝到自己项目的对应文件夹中。</p>
</li>
<li><p>Laya2.0再项目中index.js引入FGUI库：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">loadLib(&apos;libs/laya.html.js&apos;)</span><br><span class="line">loadLib(&apos;libs/rawinflate/rawinflate.min.js&apos;)</span><br><span class="line">loadLib(&apos;libs/fairygui/fairygui.js&apos;)</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/18005075-f3dd5e6386b501ac.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="引入库列表.png"></p>
</li>
<li><p>Laya1.0在项目index.html 中引入FGUI库：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;script type=&quot;text/javascript&quot; src=&quot;libs/rawinflate/rawinflate.min.js&quot;&gt;&lt;/script&gt;</span><br><span class="line">&lt;script type=&quot;text/javascript&quot; src=&quot;libs/fairygui/fairygui.js&quot;&gt;&lt;/script&gt;</span><br></pre></td></tr></table></figure></li>
<li><p>运行项目，在控制台中能正确打印 fairygui.GRoot.inst，Laya中集成FGUI就完成了，</p>
</li>
</ul>
<h1 id="四，FGUI-的使用"><a href="#四，FGUI-的使用" class="headerlink" title="四，FGUI 的使用"></a>四，FGUI 的使用</h1><ul>
<li>FGUI的使用比较简单，看看<a href="http://www.fairygui.com/guide/editor/index.html" target="_blank" rel="noopener">教程</a>即可。</li>
<li>FGUI以包为单位管理资源，使用时可以将包理解为模块，每个模块独立一个包。将发布后的文件拷贝到自己项目的bin/res目录下。</li>
<li>添加FGUI显示列表的根节点到舞台中：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Laya.stage.addChild(fairygui.GRoot.inst.displayObject);</span><br></pre></td></tr></table></figure></li>
<li>使用发布的资源包<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">   LoadPackageRes()&#123;</span><br><span class="line">	Laya.loader.load([&#123;type:Laya.Loader.BUFFER,url:&apos;res/Package1.fui&apos;&#125;],Laya.Handler.create(this,()=&gt;&#123;</span><br><span class="line">		this.AddPackageRes();</span><br><span class="line">	&#125;))</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">AddPackageRes()&#123;</span><br><span class="line">	fairygui.UIPackage.addPackage(&apos;res/Package1&apos;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>判断资源包有没有被加载:<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> if(fairygui.UIPackage.getById(&quot;res/Package1&quot;) == null)&#123;</span><br><span class="line">console.log(&apos;资源包未已加载&apos;)</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure></li>
<li>创建组件并显示到舞台上:<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">const testCom = fairygui.UIPackage.createObject(&apos;Package1&apos;,&apos;com_Test&apos;).asCom;</span><br><span class="line">fairygui.GRoot.inst.addChild(testCom);</span><br></pre></td></tr></table></figure>
完整代码：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">LoadPackageRes()&#123;</span><br><span class="line">	Laya.loader.load([&#123;type:Laya.Loader.BUFFER,url:&apos;res/Package1.fui&apos;&#125;],Laya.Handler.create(this,()=&gt;&#123;</span><br><span class="line">		this.AddPackageRes();</span><br><span class="line">	&#125;))</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">AddPackageRes()&#123;</span><br><span class="line">	if(fairygui.UIPackage.getById(&quot;res/Package1&quot;) != null)&#123;</span><br><span class="line">		console.log(&apos;资源包已加载&apos;)</span><br><span class="line">	&#125;</span><br><span class="line">	fairygui.UIPackage.addPackage(&apos;res/Package1&apos;);</span><br><span class="line">	Laya.stage.addChild(fairygui.GRoot.inst.displayObject);</span><br><span class="line">	const testCom = fairygui.UIPackage.createObject(&apos;Package1&apos;,&apos;com_Test&apos;).asCom;</span><br><span class="line">	fairygui.GRoot.inst.addChild(testCom);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
注：创建项目时注意项目类型选择LayaBox<br><img src="https://upload-images.jianshu.io/upload_images/18005075-5d0a3f521d02983f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="01.png"></li>
</ul>
<p>PS：第一次写文章，文笔不好，不喜勿喷。谢谢！</p>

      
    </div>
    <div class="article-footer">
      




    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/2019/11/23/GObject/" title="Laya FairyGui系列二  GObject  GComponent"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/2019/11/23/Laya%E4%BD%BF%E7%94%A8zip%E5%8E%8B%E7%BC%A9%E5%8C%85/" title="Laya使用zip压缩包"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
    <div class="copyright">
    	<!-- 
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div> -->
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script src="/js/plugin.min.js"></script>
<script src="/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>





   




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>